<?php
namespace Admin\Controller;
class UserController extends BaseController {
    public function wx(){
        $user=M('User');
        import('ORG.Util.Page');			//Page类的引入
        $count=$user->where($where)->count(); //获取符合条件的数据总数count
		$Page=new \Org\Util\Page($count, 10);			//实例化page类，传入数据总数和每页显示10条内容
		$show=$Page->show();
		$list=$user->where($where)->order('time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign("page",$show);
        $this->display();
    }
	public function index(){
        $object=M('User');
        import('ORG.Util.Page');			//Page类的引入
        $count=$object->where($where)->count(); //获取符合条件的数据总数count
		$Page=new \Org\Util\Page($count, 10);			//实例化page类，传入数据总数和每页显示10条内容
		$show=$Page->show();
		$list=$object->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
		$list=$object->where()->order('depid desc')
		->field('bs_User.*,b.name as dname,c.nickname as pname')
		->join('LEFT JOIN bs_Department b       ON bs_User.depId = b.id')
		->join('LEFT JOIN bs_User c       ON bs_User.pid = c.id')
		->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign("page",$show);
        $this->display();
	}
    public function editUI(){
        //$where = '(pid is null or pid=0)';
        $where = '( 1=1 )';
		if(I('get.id')){
			$this->assign('object',M('User')->where('id='.I('get.id'))->find());
			$where = $where.' and id<>'.I('get.id');
		}
        $this->assign('userlist',M('User')->where($where)->select());
        $this->assign('deplist',M('Department')->where("1=1")->select());
        $this->display('editUI');
    }
    public function editOperation(){
		$Object = M("User");   
		$Object->create();
		$id = I('post.id');
		if($id){
			if($Object->save()){
				$this->success('修改成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('修改失败');
			}
		}else{
		    $Object->password='123456';
			if($Object->add()){
				$this->success('添加成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('添加失败');
			}
		}
    }
    public function removeOperation(){
		$Object = M("User");
		if($Object->delete(I('get.id'))){
			$this->success('删除成功',U('index'));
		}else{
			dump($Object->_sql());
			$this->error('删除失败');
		}
    }
}